import json

import requests

from cache import Cache



def get(url):
    header = {'clientOs': '1', 'token': Cache.userInfo['token'], 'id': str(Cache.userInfo['id'])}
    try:
        r = requests.get(url, headers=header)
        if r.status_code == 200:
            return json.loads(r.text);
        else:
            return None
    except Exception as e:
        print(e)

def postJson(url,param):
    header = {'clientOs': '1', 'token': Cache.userInfo['token'], 'id': str(Cache.userInfo['id'])}
    try:
        r = requests.post(url,json=param,headers=header)
        if r.status_code == 200:
            return json.loads(r.text);
        else:
            return None
    except Exception as e:
        print(e)

def post(url,param):
    header = {'clientOs': '1', 'token': Cache.userInfo['token'], 'id': str(Cache.userInfo['id'])}
    try:
        r = requests.post(url, data=param, headers=header)
        if r.status_code == 200:
            return json.loads(r.text);
        else:
            return None
    except Exception as e:
        print(e)